<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title><!--{if $categoryInfo->cateType == 1}-->添加<!--{else}-->修改<!--{/if}-->商品分类</title>
    <!--{include file='comm/comm_pic.tpl'}-->
</head>

<body>
<div style="width:100%">
    <div class="items clearfix">
        <h2 style="" class="tal">
        	正在操作：
        	<!--{if $categoryInfo->cateType == 1}-->
        		添加商品分类
        	<!--{else}-->
        		修改商品<!--{if $categoryInfo->cateInfo == 1}-->大<!--{elseif $categoryInfo->cateInfo == 2}-->中<!--{elseif $categoryInfo->cateInfo == 3}-->小<!--{/if}-->分类
        	<!--{/if}-->
        </h2>
        <div class="items2">
        	<!--{if $categoryInfo->cateType == 1}-->
	            <div class="select-box">
	                <div onclick="category.change(2,1);" <!--{if $categoryInfo->cateInfo == 1}--> class="selected" <!--{/if}--> >大分类添加</div>
	                <div onclick="category.change(2,2);" <!--{if $categoryInfo->cateInfo == 2}--> class="selected" <!--{/if}--> >中分类添加</div>
	                <div onclick="category.change(2,3);" <!--{if $categoryInfo->cateInfo == 3}--> class="selected" <!--{/if}--> >小分类添加</div>
	            </div>
            <!--{/if}-->
			<div>
                <form id="category_form" onsubmit="return false;">
	                <!--{if $categoryInfo->cateInfo == 1}-->
	                	<div class="allTextTime" style="padding-bottom:10px;">
							<div style="margin:8px 0" class="input-group">
								<span style="width: 110px;" class="input-group-addon">大分类名称：</span>
								<input type="text" value="<!--{$categoryInfo->description}-->" placeholder="请输入大分类名称【必填项】" name="cateName" id="cateName" class="form-control hasDatepicker" style="padding-left:8px;">
								<input type="hidden" name="bigcategoryID" id="bigcategoryID" value="<!--{$categoryInfo->bigCategoryID}-->">
							</div>
							<div style="margin:8px 0" class="input-group">
								<span style="width: 110px;" class="input-group-addon">排列序号：</span>
								<input type="text" value="<!--{$categoryInfo->sortOrder}-->" placeholder="请输入排列序号【必填项】" name="sortOrder" id="sortOrder" class="form-control hasDatepicker" style="padding-left:8px;">
							</div>
							<div style="margin:8px 0;display:none;" class="input-group">
								<span style="width: 110px;" class="input-group-addon">使用标志：</span>
								<span placeholder="使用标志" class="form-control hasDatepicker" style="padding-left:8px;">
									<!--{if $categoryInfo->useFlg == 1}-->
	                                    <input type="radio" value="1" name="useFlg" checked /> 启用
	                                    <input type="radio" value="0" name="useFlg" /> 禁用
	                                <!--{else}-->
	                                    <input type="radio" value="1" name="useFlg" /> 启用
	                                    <input type="radio" value="0" name="useFlg" checked /> 禁用
	                                <!--{/if}-->
                                </span>
							</div>
						</div>
	 				<!--{/if}-->   
	 				      
	 				<!--{if $categoryInfo->cateInfo == 2}-->    
	 					<div class="allTextTime" style="padding-bottom:10px;">
	 						<div style="margin:8px 0" class="input-group">
								<span style="width: 110px;" class="input-group-addon">大分类：</span>
								<select placeholder="大分类" name="bigcategoryID" id="bigcategoryID" class="form-control hasDatepicker" style="width: 147px;padding-left:8px;">
									<option value="0" style="padding-left:8px;">请选择</option>
									<!--{foreach from=$bigData item=big}-->
                                		<option value="<!--{$big->bigCategoryID}-->" style="padding-left:8px;"><!--{$big->description}--></option>
                                	<!--{/foreach}-->
								</select>
							</div>
							<div style="margin:8px 0" class="input-group">
								<span style="width: 110px;" class="input-group-addon">中分类名称：</span>
								<input type="text" value="<!--{$categoryInfo->description}-->" placeholder="请输入中分类名称【必填项】" name="cateName" id="cateName" class="form-control hasDatepicker" style="padding-left:8px;">
								<input type="hidden" name="midcategoryID" id="midcategoryID" value="<!--{$categoryInfo->midCategoryID}-->">
							</div>
							<div style="margin:8px 0" class="input-group">
								<span style="width: 110px;" class="input-group-addon">排列序号：</span>
								<input type="text" value="<!--{$categoryInfo->sortOrder}-->" placeholder="请输入排列序号【必填项】" name="sortOrder" id="sortOrder" class="form-control hasDatepicker" style="padding-left:8px;">
							</div>
							<div style="margin:8px 0;display:none;" class="input-group">
								<span style="width: 110px;" class="input-group-addon">使用标志：</span>
								<span placeholder="使用标志" class="form-control hasDatepicker" style="padding-left:8px;">
									<!--{if $categoryInfo->useFlg == 1}-->
										
	                                    <input type="radio" value="1" name="useFlg" checked /> 启用
	                                    <input type="radio" value="0" name="useFlg" /> 禁用
	                                <!--{else}-->
	                                    <input type="radio" value="1" name="useFlg" /> 启用
	                                    <input type="radio" value="0" name="useFlg" checked /> 禁用
	                                <!--{/if}-->
                                </span>
							</div>
						</div>
                    <!--{/if}-->
                    
                    <!--{if $categoryInfo->cateInfo == 3}-->
                    	<div class="allTextTime" style="padding-bottom:10px;">
	 						<div style="margin:8px 0" class="input-group">
								<span style="width: 110px;" class="input-group-addon">大分类：</span>
								<select placeholder="大分类" name="bigcategoryID" id="bigcategoryID" class="form-control hasDatepicker" onchange="category.getCategory();" style="width: 147px;padding-left:8px;">
									<option value="0" style="padding-left:8px;">请选择</option>
									<!--{foreach from=$bigData item=big}-->
                                		<option value="<!--{$big->bigCategoryID}-->" style="padding-left:8px;"><!--{$big->description}--></option>
                                	<!--{/foreach}-->
								</select>
							</div>
							<div style="margin:8px 0" class="input-group">
								<span style="width: 110px;" class="input-group-addon">中分类：</span>
								<select placeholder="中分类" name="midcategoryID" id="midcategoryID" class="form-control hasDatepicker" style="width: 147px;padding-left:8px;">
									<option value="0" style="padding-left:8px;">请选择</option>
									<!--{if isset($midData)}-->
										<!--{foreach from=$midData item=mid}-->
		                            		<option value="<!--{$mid->midCategoryID}-->" style="padding-left:8px;"><!--{$mid->description}--></option>
		                            	<!--{/foreach}-->
	                            	<!--{/if}-->
								</select>
							</div>
							<div style="margin:8px 0" class="input-group">
								<span style="width: 110px;" class="input-group-addon">小分类名称：</span>
								<input type="text" value="<!--{$categoryInfo->description}-->" placeholder="请输入小分类名称【必填项】" name="cateName" id="cateName" class="form-control hasDatepicker" style="padding-left:8px;">
								<input type="hidden" name="smallcategoryID" id="smallcategoryID" value="<!--{$categoryInfo->smallCategoryID}-->">
							</div>
							<div style="margin:8px 0" class="input-group">
								<span style="width: 110px;" class="input-group-addon">排列序号：</span>
								<input type="text" value="<!--{$categoryInfo->sortOrder}-->" placeholder="请输入排列序号【必填项】" name="sortOrder" id="sortOrder" class="form-control hasDatepicker" style="padding-left:8px;">
							</div>
							<div style="margin:8px 0;display:none;" class="input-group">
								<span style="width: 110px;" class="input-group-addon">使用标志：</span>
								<span placeholder="使用标志" class="form-control hasDatepicker" style="padding-left:8px;">
									<!--{if $categoryInfo->useFlg == 1}-->
	                                    <input type="radio" value="1" name="useFlg" checked /> 启用
	                                    <input type="radio" value="0" name="useFlg" /> 禁用
	                                <!--{else}-->
	                                    <input type="radio" value="1" name="useFlg" /> 启用
	                                    <input type="radio" value="0" name="useFlg" checked /> 禁用
	                                <!--{/if}-->
                                </span>
							</div>
						</div>
                    <!--{/if}-->
                    
                    <!--商品标签组-->
                    <div class="select-box" style="margin-top:30px;">
                    	<div>标签组</div>
                    </div>
                    <table style="width:97%;border-collapse:collapse;table-layout:fixed;">
						<tr style="height:30px;">
						<!--{assign var="listCount" value=0}-->
						<!--{foreach from=$tag_group item=group_line}-->
							<!--{assign var="isChecked" value=""}-->
							<!--{foreach from=$category_tag item=category_line}-->
								<!--{if $category_line->tagGroupID == $group_line->tagGroupID}-->
									<!--{assign var="isChecked" value="checked"}-->
								<!--{/if}-->
							<!--{/foreach}-->
							<!--{if $listCount>0 && $listCount%7 == 0}-->
								</tr><tr style="height:30px;">
							<!--{/if}-->
							<td style="width:13%;overflow:hidden;white-space:nowrap;padding-left:5px;" title="<!--{$group_line->memo_tagGroupName}-->">
								<input style="text-align:left;" type="checkbox" id="chk_<!--{$group_line->tagGroupID}-->" name="groupID[]" <!--{$isChecked}--> value="<!--{$group_line->tagGroupID}-->">
								<!--{$group_line->tagGroupName}-->
							</td>
							<!--{assign var="listCount" value=$listCount+1}-->
						<!--{/foreach}-->
						</tr>
					</table>
					
					<!--商品规格组-->
					<div class="select-box" style="margin-top:30px;">
                    	<div>规格组</div>
                    </div>     
                     <table style="width:97%;border-collapse:collapse;table-layout:fixed;">
						<tr style="height:30px;">
						<!--{assign var="listCount" value=0}-->
						<!--{foreach from=$spec_group item=group_line}-->
							<!--{assign var="isChecked" value=""}-->
							<!--{foreach from=$category_spec item=category_line}-->
								<!--{if $category_line->specGroupID == $group_line->specGroupID}-->
									<!--{assign var="isChecked" value="checked"}-->
								<!--{/if}-->
							<!--{/foreach}-->
							<!--{if $listCount>0 && $listCount%3 == 0}-->
								</tr><tr style="height:30px;">
							<!--{/if}-->
							<td style="width:13%;overflow:hidden;white-space:nowrap;padding-left:5px;" title="<!--{$group_line->memo_specGroupName}-->">
								<input style="text-align:left;" type="checkbox" id="chk_<!--{$group_line->specGroupID}-->" name="specGroupID[]" <!--{$isChecked}--> value="<!--{$group_line->specGroupID}-->">
								<!--{$group_line->specGroupName}-->
							</td>
							<!--{assign var="listCount" value=$listCount+1}-->
						<!--{/foreach}-->
						</tr>
					</table>
                    
                </form>
            </div>
        </div>
    </div>
	<div style="margin-top:50px;">&nbsp;</div>

    <div class="bottom_fixbox">
        <div class="rectbox tac">
            <input type="button" class="btn" onclick="category.check();" value="<!--{if $categoryInfo->cateType == 1}-->添加<!--{else}-->修改<!--{/if}-->分类" />&nbsp;&nbsp;&nbsp;
            <input type="button" class="btn" onclick="E.closeWindows();" value="关闭" />
        </div>
    </div>


</div>

<script type="text/javascript">

	<!--{if $categoryInfo->bigCategoryID != '' && $categoryInfo->bigCategoryID != null}-->
    	$('#bigcategoryID').val('<!--{$categoryInfo->bigCategoryID}-->');
    <!--{/if}-->
    
    <!--{if $categoryInfo->midCategoryID != '' && $categoryInfo->midCategoryID != null}-->
    	$('#midcategoryID').val('<!--{$categoryInfo->midCategoryID}-->');
    <!--{/if}-->

    var category = {
    	
        category_id: <!--{$category_id|default:0}-->,
        cate_info  : <!--{$categoryInfo->cateInfo|default:1}-->,
        
        //检查数据
        check: function() {
            this.dt = E.getFormValues("category_form");
            var error_msg = "";
            if (this.dt.cateName == "")
                error_msg += "分类名称不能为空<br />";
            if (!E.isInt(this.dt.sortOrder) || this.dt.sortOrder <= 0)
                error_msg += "分类排序不正确<br />";
  
            if(this.cate_info == 2){
            	if(!E.isInt(this.dt.bigcategoryID) || this.dt.bigcategoryID <= 0)
            		error_msg += "请选择大分类<br />";
            }else if(this.cate_info == 3){
            	if(!E.isInt(this.dt.bigcategoryID) || this.dt.bigcategoryID <= 0)
            		error_msg += "请选择大分类<br />";
            		
            	if(!E.isInt(this.dt.midcategoryID) || this.dt.midcategoryID <= 0)	
            		error_msg += "请选择中分类<br />";	
            }
                
            if (error_msg != "")
                E.alert(error_msg);
            else
                E.confirm("您确认要<!--{if $categoryInfo->cateType == 1}-->添加<!--{else}-->修改<!--{/if}-->商品分类信息吗？", "category.add");
        },

        //保存资源位信息
        add: function() {
        	//获取选中的标签组
        	var tgroupArr = [];
        	$('[name*=groupID]:checked').each(function(){
        		tgroupArr.push($(this).val());
        	})
			//获取选中的规格组
			var sgroupArr = [];
			$('[name*=specGroupID]:checked').each(function(){
				sgroupArr.push($(this).val());
			});
        	var dataInfo = {formVal : this.dt, tVal : tgroupArr, gVal : sgroupArr};
        	
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/goods/category.ajax?operFlg=2&cateInfo="+this.cate_info,
                dataType: "JSON",
                data: dataInfo,
                success: function( result_obj ) {
                    if (result_obj.code == 200) {
                    	if(result_obj.jump == 1)
	                        E.alert(result_obj.message, 2, 'E.closeWindows');
                    	else
                    		E.alert(result_obj.message, 2, 'E.refresh');	
                    		
                    	 E.opener('E.refresh');	
                    	
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },

        //切换标签
        change: function(operFlg, cateFlg) {
            if (this.category_id)
                self.location = "/quanliadmin/app/goods/goodsCategory.pscript?operFlg=" + operFlg + "&category_id=" + this.category_id;
            else
                self.location = "/quanliadmin/app/goods/goodsCategory.pscript?operFlg=" + operFlg + '&cateFlg=' + cateFlg;
        },
        
        //根据大分类号查询中分类信息
        getCategory : function(){
        	var bigID = $('#bigcategoryID').val();
        	if(bigID == 0)
        		$('#midcategoryID').html('<option value="0">请选择</option>');
        	else{
        		//ajax查询
        		$.ajax({
        			type: 'POST',
        			url : "/invokingAjax-backend/goods/category.ajax?operFlg=6&bigID="+bigID,
        			 success: function(result) {
        			 	
        			 	if(result == null)
        			 		$('#midcategoryID').html('<option value="0" style="padding-left:8px;">请选择</option>');
        			 	else{	
        			 		result = eval('(' + result + ')');
        			 		
	        			 	var str = '<option value="0" style="padding-left:8px;">请选择</option>';
	        			 	$.each(result, function(k, v){
	        			 		str += '<option value='+k+' style="padding-left:8px;">'+v+'</option>';
	        			 	})
	        			 	
	        			 	$('#midcategoryID').html(str);
        			 	}
        			 }
        		});
        	}
        }
    };

    $(document).ready(function() {
        $('.fancybox').fancybox();

    });
</script>

</body>

</html>
